//
//  XFDLogInScrollView.m
//  XFDLogin_Example
//
//  Created by 韩冰 on 2017/11/3.
//  Copyright © 2017年 GL-ZHU. All rights reserved.
//

#import "XFDLogInScrollView.h"
#import "XFDLogInPassWordView.h"
#import "XFDLogInVerificationCodeView.h"
#import "XFDLogInForgetView.h"
#import <Masonry/Masonry.h>
#import <XFDCommon/HBCommon.h>

@interface XFDLogInScrollView ()

@property (nonatomic, strong)XFDLogInPassWordView *passWordView;
@property (nonatomic, strong)XFDLogInVerificationCodeView *codeView;
@property (nonatomic, strong)XFDLogInForgetView *forgetView;


@end

@implementation XFDLogInScrollView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.codeView];
        [self addSubview:self.passWordView];
        [self addSubview:self.forgetView];
        self.scrollEnabled = NO;
        self.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
    }
    return self;
}
- (void)scrollToCodeView{
    [self scrollToPoit:CGPointMake(0, 0)];
}
- (void)scrollToForgetView{
    [self scrollToPoit:CGPointMake(SCREEN_WIDTH*2, 0)];
 
}
- (void)scrollToPassWordView{
    [self scrollToPoit:CGPointMake(SCREEN_WIDTH, 0)];
}
- (void)loginForCodeTimeAction{
    [self.codeView codeButtonAction];
}
- (void)forgetForCodeTimeAction{
    [self.forgetView codeButtonAction];
}
- (void)scrollToPoit:(CGPoint)poit{
    
    [UIView animateWithDuration:0.3 animations:^{
        self.contentOffset = poit;
    }];
    
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    self.codeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.height);
     self.passWordView.frame = CGRectMake(SCREEN_WIDTH ,0 , SCREEN_WIDTH, self.height);
     self.forgetView.frame = CGRectMake(SCREEN_WIDTH*2 , 0, SCREEN_WIDTH, self.height);
}

- (XFDLogInPassWordView *)passWordView{
    if (!_passWordView) {
        _passWordView = [[XFDLogInPassWordView alloc]init];
        _passWordView.backgroundColor= [UIColor whiteColor];
        WEAKSELF
        _passWordView.forgetPassWordBlock = ^{
            STRONGSELF
            if (strongSelf.clickForgetPassWordBlock) {
                strongSelf.clickForgetPassWordBlock();
            }
        };
        _passWordView.logInBlock = ^(NSString *phoneNum, NSString *passWord) {
            STRONGSELF
            if (strongSelf.logInPassWordBlock) {
                strongSelf.logInPassWordBlock(phoneNum,passWord);
            }
        };
    }
    return _passWordView;
    
}

- (XFDLogInVerificationCodeView *)codeView{
    if (!_codeView) {
        _codeView = [[XFDLogInVerificationCodeView alloc]init];
        _codeView.backgroundColor= [UIColor whiteColor];
        WEAKSELF
        _codeView.logInBlock = ^(NSString *phoneNum, NSString *passWord) {
            STRONGSELF
            
            if (strongSelf.logInCodeBlock) {
                strongSelf.logInCodeBlock(phoneNum,passWord);
            }
        };
        _codeView.getLogInCodeBlock = ^(NSString *phone) {
            STRONGSELF
            if (strongSelf.clickLogInCodeBlock){
                strongSelf.clickLogInCodeBlock(phone);
            }
        };
    }
    return _codeView;
}
- (XFDLogInForgetView *)forgetView{
    if (!_forgetView) {
        _forgetView = [[XFDLogInForgetView alloc]init];
        _forgetView.backgroundColor= [UIColor whiteColor];
        WEAKSELF
        _forgetView.forgetBlock = ^(NSMutableDictionary *dict) {
            STRONGSELF
            
            if (strongSelf.findPassWordBlock) {
                strongSelf.findPassWordBlock(dict);
            }
        };
        _forgetView.forgetGetCodeBlock = ^(NSString *phone) {
            STRONGSELF

            if (strongSelf.clickForgetCodeBlock) {
                strongSelf.clickForgetCodeBlock(phone);
            }
        };
    }
    return _forgetView;
}



@end
